package org.lifei.base.service.impl;

import org.lifei.base.mapper.BaseMapper;
import org.lifei.base.query.BaseQuery;
import org.lifei.base.service.IBaseService;
import org.lifei.base.util.PageInfo;
import org.lifei.org.domain.Department;
import org.lifei.org.mapper.DepartmentMapper;
import org.lifei.org.query.Departmentquery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.List;

public class BaseServiceImpl<T> implements IBaseService<T> {
    @Autowired
    private BaseMapper<T> mapper;

    @Override
    @Transactional
    public void insert(T t) {
        mapper.insert(t);

    }

    @Override
    @Transactional
    public void delete(Serializable id) {
        mapper.delete(id);
    }

    @Override
    @Transactional
    public void update(T t) {
        mapper.update(t);
    }

    @Override
    @Transactional
    public void batchDelete(List<String> ids) {
        mapper.batchDelete(ids);
    }

    @Override
    public T queryOne(Serializable id) {
        return mapper.queryOne(id);
    }

    @Override
    public List<T> queryAll() {
        return mapper.queryAll();
    }

    @Override
    public PageInfo<T> queryPage(BaseQuery baseQuery) {
        //查询总条数  需要根据传入参数进行查询
        long total = mapper.queryTotal(baseQuery);
        if (total == 0){
            return new PageInfo<>();
        }
        //查询数据
        List<T> list=mapper.queryList(baseQuery);

        return new PageInfo<>(total,list);
    }
}
